package com.ruoyi.bizsys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.bizsys.domain.AppUser;
import com.ruoyi.bizsys.dto.UserInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 用户Mapper接口
 *
 * @author african-loan
 * @date 2021-12-30
 */
public interface AppUserMapper extends BaseMapper<AppUser> {

    /**
     * 查询安装未注册用户
     *
     * @return
     */
    List<String> selectUnRegisterUserList();

    UserInfo getUserInfoByUserId(String userId);

    UserInfo getUserInfoByCustNo(String custNo);

    List<AppUser> getAppUserListByCustNos(String custNos);

    List<Map<String, String>> getIncreasedLimitPhone(@Param("custNos") String custNos);

    AppUser getValidInviter(@Param("inviteCode") String inviteCode);

    /**
     * 通过uuid改变用户状态
     *
     * @param userId
     * @param code
     */
    @Update("update app_user set state=#{code} where user_uuid=#{userId} ")
    void updateAppUserToCancellation(@Param("userId") String userId, @Param("code") String code);

    /**
     * 通过手机号查询有效状态用户个数
     *
     * @param phone
     * @return
     */
    @Select("select user_id from app_user where  phone =#{phone} and state =0 limit 1;")
    AppUser selectUser(String phone);

    /**
     * 通过手机号查询所有用户个数
     *
     * @param phone
     * @return
     */
    @Select("select count(user_id) from app_user where  phone =#{phone} limit 1;")
    int countall(String phone);

    /**
     * 通过用户uuid查询手机号
     *
     * @param userId
     * @return
     */
    @Select("select user_uuid, phone, country_code,bvn from app_user where user_uuid=#{userId} and state=0")
    AppUser selectPhoneByUserId(String userId);

    @Select("SELECT user_id FROM app_user WHERE LENGTH(invite_code) != 6 ORDER BY user_id")
    List<Long> get8DigitInviteCodeUser();

    List<String> getInviteList(@Param("inviteList") List<String> inviteList);

    @Select("SELECT phone FROM app_user WHERE user_uuid=#{userId} and state=0")
    String selectAppUserByPhone(String userId);
}
